<template>
  <div v-if="show" class="back-to-top" @click.stop="backTop">
    <div class="up-icon mb-16">
      <icon size="24px" name="ic_arrow_db_up" />
    </div>

    <div>
      <img
        src="@/assets/images/qr_code_km.png"
        alt=""
        class="img img-cover mb-4"
      />
      <p class="title">
        {{ $t('Scan_QR_code') }}
      </p>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      show: false
    };
  },

  mounted() {
    this.init();
  },

  beforeDestroy() {
    this.removeListeners();
  },

  methods: {
    init() {
      if (process.server) return;
      this.check();
      window.addEventListener('scroll', this.check);
    },
    removeListeners() {
      if (process.server) return;
      window.removeEventListener('scroll', this.check);
    },
    check() {
      const { scrollY } = window;
      const height = window.innerHeight;
      this.show = scrollY > height * 1.5;
    },
    backTop() {
      window.scrollTo(0, 0);
    }
  }
};
</script>

<style lang="scss" scoped>
.back-to-top {
  width: 80px;

  .up-icon {
    width: 40px;
    height: 40px;
    padding: 8px;
    background: #ffffff;
    border: 0.5px solid rgba(12, 12, 28, 0.2);
    border-radius: 8px;
  }

  .img {
    width: 80px;
    height: 80px;
  }
  .title {
    font-size: 12px;
    color: rgba(12, 12, 28, 0.7);
    letter-spacing: 0;
    text-align: center;
    line-height: 16px;
  }
}
</style>
